//
//  Contact_DetailViewController.m
//  HuaRun2
//
//  Created by admin on 17/9/2.
//  Copyright © 2017年 Sunny. All rights reserved.
//

#import "Contact_DetailViewController.h"
#import "Contact_DetailHeaderView.h"
#import "ImageLabView.h"
#import "Contact_DetailPrivateLifeCell2.h"
#import "AddressTableViewCell.h"
#import "Contact_DetailModel.h"
#import "Contact_ListModel.h"
#import "AddressModel.h"
#import "Contact_CusTableViewController.h"
#import "Contact_RoleModel.h"
#import "GiftModel.h"
#import "Com_MeetingModel.h"
#import "CustomerTableViewController.h"
#import "NoteTableViewController.h"
#import "Contact_DetailBaseInfoCell3.h"
#import "Contact_DetailWorkRelationCell2.h"
#import "Add_Manual_ContactViewController.h"
#import "Home_Search_NoteCell.h"
#import "Contact_ReportModel.h"
#import "EditWorkInfoViewController.h"
#import "EditPrivateInfoViewController.h"

@interface Contact_DetailViewController ()
@property(nonatomic, strong)Contact_DetailModel * detailModel;
@end

@implementation Contact_DetailViewController
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self fetchContactPersonDetail];
    [self fetchContactAddressListIsPrivate:YES];
    [self fetchContactAddressListIsPrivate:NO];
    
//    [self fetchContactGifNum];
    [self fetchContactMeetingNum];
    [self fetchContactPersonNum];
    [self fetchContactReportList];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    
    self.navigationItem.title = NSLocalizedString(@"contact_detail", nil);
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.showsHorizontalScrollIndicator = NO;
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleDone target:nil action:nil];
    self.navigationItem.backBarButtonItem = backItem;

    //下两行结合用，自动计算高度
    self.tableView.estimatedRowHeight = 213;
//    self.tableView.rowHeight = UITableViewAutomaticDimension;
    
    [self.tableView registerClass:[UITableViewCell class]
           forCellReuseIdentifier:@"cell"];
    [self.tableView registerClass:[Contact_DetailBaseInfoCell3 class]
           forCellReuseIdentifier:@"Contacct_DetailBaseInfoCell"];
    [self.tableView registerClass:[Contact_DetailWorkRelationCell2 class]
           forCellReuseIdentifier:@"Contact_DetailWorkRelationCell"];
    [self.tableView registerClass:[Contact_DetailPrivateLifeCell2 class]
           forCellReuseIdentifier:@"Contact_DetailPrivateLifeCell"];
    [self.tableView registerClass:[AddressTableViewCell class]
       forCellReuseIdentifier:@"AddressTableViewCell"];
    [self.tableView registerClass:[Home_Search_NoteCell class]
           forCellReuseIdentifier:@"Home_Search_NoteCell"];

    Contact_DetailHeaderView * headerView = [Contact_DetailHeaderView new];
    headerView.frame = CGRectMake(0, 0, kMainScreenWidth, 145);
    self.tableView.tableHeaderView = headerView;

    [self methodBind];
}
//重新设置头部名称
- (void)reConfigureHeaderViewName {
    Contact_DetailHeaderView * headerView = (Contact_DetailHeaderView * ) self.tableView.tableHeaderView;
    headerView.leaveView.hidden = [_detailModel.resigned intValue] == 0;
    headerView.refuseView.hidden = [_detailModel.emailBounceBack intValue] == 0;
 
    ////    salutation + lastName + firstName
    headerView.nameLab.text = [NSString stringWithFormat:@"%@ %@ %@",
                               [NSString showSpaceStringWithStr: _detailModel.salutation],
                               [NSString showSpaceStringWithStr: _detailModel.firstName],
                               [NSString showSpaceStringWithStr: _detailModel.lastName]];
    headerView.companyLab.text = [NSString showSpaceStringWithStr:_detailModel.nameChinese];
}

- (void)methodBind {
    weakself(ws);
    
    Contact_DetailHeaderView * headerView = (Contact_DetailHeaderView * )self.tableView.tableHeaderView;
    
    [headerView.noteView clickViewBlock:^(UIGestureRecognizer *gestureRecoginzer) {
        [ws seeNote];
    }];
    
    [headerView.roleView clickViewBlock:^(UIGestureRecognizer *gestureRecoginzer) {
        [ws seeContact];
    }];
    
    [headerView.meetingView clickViewBlock:^(UIGestureRecognizer *gestureRecoginzer) {
        [ws seeMeeting];
    }];
    
    [headerView.giftView clickViewBlock:^(UIGestureRecognizer *gestureRecoginzer) {
//        [ws seeGift];
        [ws seeSysReportList];

    }];
    
    [headerView.sysReportView clickViewBlock:^(UIGestureRecognizer *gestureRecoginzer) {
        [ws seeSysReportList];
    }];
}

//查看系统记录
- (void)seeSysReportList {
    if (_reportArray.count ==0) {
        [self showAlert:NSLocalizedString(@"暂无数据", nil)];
        return;
    }
    
    Contact_CusTableViewController* customer = [Contact_CusTableViewController new];
    customer.contact_CusListType = Contact_CusListTypeReport;
    customer.dataArray = _reportArray;
    customer.contactId = _detailModel.id ? _detailModel.id : @"";
    customer.name = [NSString stringWithFormat:@"%@ %@ %@",
                     [NSString showStringWithStr: _detailModel.salutation],
                     [NSString showStringWithStr: _detailModel.firstName],
                     [NSString showStringWithStr: _detailModel.lastName]];
    customer.companyName = [NSString showSpaceStringWithStr:_detailModel.nameChinese];
    [self.navigationController pushViewController:customer animated:YES];

}

//查看备注
- (void)seeNote {
    NoteTableViewController * customer = [NoteTableViewController new];
    customer.parentId = _detailModel.id ? _detailModel.id : @"";
    customer.noteType = NoteTypeContact;
    customer.name = [NSString stringWithFormat:@"%@ %@ %@",
                     [NSString showStringWithStr: _detailModel.salutation],
                     [NSString showStringWithStr: _detailModel.firstName],
                     [NSString showStringWithStr: _detailModel.lastName]];
    customer.companyName = [NSString showSpaceStringWithStr:_detailModel.nameChinese];
    [self.navigationController pushViewController:customer animated:YES];

}

//查看角色
- (void)seeContact {
    if (_contactPersonsArray.count ==0) {
        [self showAlert:NSLocalizedString(@"暂无数据", nil)];
        return;
    }
    
    Contact_CusTableViewController* customer = [Contact_CusTableViewController new];
    customer.contact_CusListType = Contact_CusListTypeRole;
    customer.dataArray = _contactPersonsArray;
    customer.name = [NSString stringWithFormat:@"%@ %@ %@",
                     [NSString showStringWithStr: _detailModel.salutation],
                     [NSString showStringWithStr: _detailModel.firstName],
                     [NSString showStringWithStr: _detailModel.lastName]];
    customer.companyName = [NSString showSpaceStringWithStr:_detailModel.nameChinese];
    [self.navigationController pushViewController:customer animated:YES];
}

//查看系统记录
- (void)seeReport {
    if (_contactPersonsArray.count ==0) {
        [self showAlert:NSLocalizedString(@"暂无数据", nil)];
        return;
    }

    Contact_CusTableViewController* customer = [Contact_CusTableViewController new];
    customer.contact_CusListType = Contact_CusListTypeReport;
    customer.dataArray = _contactPersonsArray;
    customer.contactId = _contactId;
    customer.name = [NSString stringWithFormat:@"%@ %@ %@",
                     [NSString showStringWithStr: _detailModel.salutation],
                     [NSString showStringWithStr: _detailModel.firstName],
                     [NSString showStringWithStr: _detailModel.lastName]];
    customer.companyName = [NSString showSpaceStringWithStr:_detailModel.nameChinese];

    [self.navigationController pushViewController:customer animated:YES];
}
//查看会议
- (void)seeMeeting {
    if (_meetingsArray.count ==0) {
        [self showAlert:NSLocalizedString(@"暂无数据", nil)];
        return;
    }

    CustomerTableViewController * customer = [CustomerTableViewController new];
    customer.listType = ListTypeMeetiong;
    customer.dataArray = _meetingsArray;
    customer.name = [NSString stringWithFormat:@"%@ %@ %@",
     [NSString showStringWithStr: _detailModel.salutation],
     [NSString showStringWithStr: _detailModel.firstName],
     [NSString showStringWithStr: _detailModel.lastName]];
    customer.companyName = [NSString showSpaceStringWithStr:_detailModel.nameChinese];
    customer.navigationItem.title = NSLocalizedString(@"contact_detail_meeting", nil);
    [self.navigationController pushViewController:customer animated:YES];
}

//查看礼物
- (void)seeGift {
    if (_giftsArray.count ==0) {
        [self showAlert:NSLocalizedString(@"暂无数据", nil)];
        return;
    }

    CustomerTableViewController * customer = [CustomerTableViewController new];
    customer.listType = ListTypeGift;
    customer.name = [NSString stringWithFormat:@"%@ %@ %@",
                     [NSString showStringWithStr: _detailModel.salutation],
                     [NSString showStringWithStr: _detailModel.firstName],
                     [NSString showStringWithStr: _detailModel.lastName]];
    customer.companyName = [NSString showSpaceStringWithStr:_detailModel.nameChinese];
    customer.dataArray = _giftsArray;
    customer.navigationItem.title = NSLocalizedString(@"contact_detail_gift", nil);
    [self.navigationController pushViewController:customer animated:YES];
    
}
    
    //#pragma mark - method
    //查看地址详情
- (void)seeAddressDetail:(AddressModel *)addressModel{
    NSString * name = [NSString stringWithFormat:@"%@ %@ %@",
                       [NSString showSpaceStringWithStr: _detailModel.salutation],
                       [NSString showSpaceStringWithStr: _detailModel.firstName],
                       [NSString showSpaceStringWithStr: _detailModel.lastName]];
    NSString * companyName = [NSString showSpaceStringWithStr:_detailModel.nameChinese];
    
    CustomerTableViewController * customer = [CustomerTableViewController new];
    customer.listType = ListTypeAddress;
    customer.name = name;
    customer.companyName = companyName;
    customer.addressModel = addressModel;
    [self.navigationController pushViewController:customer animated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 5;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
   return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        Contact_DetailBaseInfoCell3 *cell = [tableView dequeueReusableCellWithIdentifier:@"Contacct_DetailBaseInfoCell"
                                                                            forIndexPath:indexPath];
        cell.detailModel = _detailModel;
        [self operateBaseInfoMethod: cell];
        return cell;
        
    }else if (indexPath.section == 2) {
        Contact_DetailWorkRelationCell2 *cell = [tableView dequeueReusableCellWithIdentifier:@"Contact_DetailWorkRelationCell"
                                                                            forIndexPath:indexPath];
        cell.detailModel = _detailModel;
        [self operateWorkRelationMethod:cell];
        return cell;
    
    }else if (indexPath.section == 3) {
        Contact_DetailPrivateLifeCell2 *cell = [tableView dequeueReusableCellWithIdentifier:@"Contact_DetailPrivateLifeCell"
                                                                               forIndexPath:indexPath];
        cell.detailModel = _detailModel;
        return cell;
        
    } else if (indexPath.section == 1 || indexPath.section == 4) {
        //办公地址为空
        if (_officeAddressArray.count == 0 && indexPath.section == 1) {
            Home_Search_NoteCell * cell = [tableView dequeueReusableCellWithIdentifier:@"Home_Search_NoteCell"
                                                                          forIndexPath:indexPath];
            cell.valueLab1.text = NSLocalizedString(@"暂无数据", nil);
            return cell;
        }
        
        if (_privateAddressArray.count == 0 && indexPath.section == 4) {
            Home_Search_NoteCell * cell = [tableView dequeueReusableCellWithIdentifier:@"Home_Search_NoteCell"
                                                                          forIndexPath:indexPath];
            cell.valueLab1.text = NSLocalizedString(@"暂无数据", nil);
            return cell;
        }
        
        AddressTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"AddressTableViewCell"
                                                                      forIndexPath:indexPath];
        if (indexPath.section == 1) {
            cell.addressArray =  _officeAddressArray;
        }else {
            cell.addressArray = _privateAddressArray;
        }
        
        weakself(ws);
        cell.clickBlock = ^(NSInteger index) {
            AddressModel * addressModel ;
            if (indexPath.section == 1) {
                addressModel = ws.officeAddressArray[index];
            }else {
                addressModel = ws.privateAddressArray[index];
            }
            [ws seeAddressDetail:addressModel];
        };
        return cell;
    }
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"
                                                            forIndexPath:indexPath];
    return cell;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        
        UIView * view = [self makeCommonSectionHeaderViewWithText:NSLocalizedString( @"基本信息", nil)];
        UIButton * btn = [UIButton new];
        btn.frame = CGRectMake(kMainScreenWidth - 40, 10, 30, 30);
        [btn setImage:[UIImage imageNamed:@"编辑001"]
                       forState:(UIControlStateNormal)];
        [btn addTarget:self action:@selector(editContactMethod) forControlEvents:(UIControlEventTouchUpInside)];
//        btn.backgroundColor = [UIColor redColor];
        [view addSubview:btn];
        
        return view;
    }else if (section == 2) {

        //        "working_relation"= "工作关系";
         UIView * view = [self makeCommonSectionHeaderViewWithText:NSLocalizedString(@"working_relation", nil)];
//                 @"工作关系"];
        
        UIButton * btn = [UIButton new];
        btn.frame = CGRectMake(kMainScreenWidth - 40, 10, 30, 30);
        [btn setImage:[UIImage imageNamed:@"编辑001"]
             forState:(UIControlStateNormal)];
        [btn addTarget:self action:@selector(editWorkInfo) forControlEvents:(UIControlEventTouchUpInside)];
        [view addSubview:btn];
        
        return view;
        
    }else if (section == 3) {
        
        //        "private_life"= "私人生活";
         UIView * view = [self makeCommonSectionHeaderViewWithText:NSLocalizedString(@"private_life", nil)];
//                 @"私人生活"];
        UIButton * btn = [UIButton new];
        btn.frame = CGRectMake(kMainScreenWidth - 40, 10, 30, 30);
        [btn setImage:[UIImage imageNamed:@"编辑001"]
             forState:(UIControlStateNormal)];
        [btn addTarget:self action:@selector(editPrivateInfo) forControlEvents:(UIControlEventTouchUpInside)];
        [view addSubview:btn];

        return view;
    }else if (section == 1) {
        
        //        "company_address_count1"= "办公地址";
        NSString * numberStr = _officeAddressArray.count > 0 ?
        [NSString stringWithFormat:@"(%ld)", self.officeAddressArray.count] : @"";
        
        NSString * text = [NSString stringWithFormat:@"%@%@",
                      NSLocalizedString(@"company_address_count1", nil),
                      numberStr];
        return [self makeCommonSectionHeaderViewWithText:text];
//                 @"办公地址"];
    }else if (section == 4) {
        //        "company_address_count2"= "私人地址";
        NSString * numberStr = _privateAddressArray.count > 0 ?
        [NSString stringWithFormat:@"(%ld)", self.privateAddressArray.count] : @"";
        NSString * text = [NSString stringWithFormat:@"%@%@",
                           NSLocalizedString(@"company_address_count2", nil),
                           numberStr];

        return  [self makeCommonSectionHeaderViewWithText:text];
//                 @"私人地址"];
    }
    return [UIView new];
}

- (UIView *)makeCommonSectionHeaderViewWithText:(NSString *)text {
    
    UIView * view = [[UIView alloc] initWithFrame:(CGRectMake(0, 0, kMainScreenWidth, 50))];
    view.backgroundColor = RGBA(249, 249, 249, 1);
    
    UILabel * label = [[UILabel alloc] init];
    label.frame = CGRectMake(10, 10, 150, 20);
    label.font = kFontSize15;
    label.text = text;
    label.textColor = [UIColor colorWithHex:@"3c3c3c"];
    [view addSubview:label];
    
    return view;

}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 40;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 1) {
        if (_officeAddressArray.count == 0) {
            return 44;
        }
        return 164;
    }
    if (indexPath.section == 4) {
        if (_privateAddressArray.count == 0) {
            return 44;
        }
        return 164;
    }
    
    return UITableViewAutomaticDimension;// self.tableView.rowHeight;
}

    
- (void)operateWorkRelationMethod:(Contact_DetailWorkRelationCell2 *)cell {
    weakself(ws);
    
    [cell.phone1ValueLab addTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
        [ws callMethodWithNumber:ws.detailModel.assistantTel];
    }];
    
    [cell.phone2ValueLab addTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
        [ws callMethodWithNumber:ws.detailModel.assistantMobile];
    }];
    
    [cell.email1ValueLab addTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
//        [ws copyTextToPasteboardWithText:ws.detailModel.accountName];
        [ToolHelper openEamilWithEmailStr:ws.detailModel.accountName];
    }];
    
}
    
- (void)operateBaseInfoMethod:(Contact_DetailBaseInfoCell3 *)cell {
    
    weakself(ws);
    [cell.phone1ValueLab addTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
        [ws callMethodWithNumber:ws.detailModel.hkMobile];
    }];
    
    [cell.phone2ValueLab addTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
        [ws callMethodWithNumber:ws.detailModel.chinaMobile];
    }];
    
    [cell.email1ValueLab addTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
        
//        [ws copyTextToPasteboardWithText:ws.detailModel.email];
        [ToolHelper openEamilWithEmailStr:ws.detailModel.email];
    }];
    
    [cell.email2ValueLab addTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
        
//        [ws callMethodWithNumber:ws.detailModel.email2];
        [ToolHelper openEamilWithEmailStr:ws.detailModel.email2];
    }];
    
}
    
- (void)callMethodWithNumber:(NSString *)number {
    [ToolHelper callWithPhoneNum:number];
}
    
- (void)copyTextToPasteboardWithText:(NSString *)text {
    
    BOOL isCanCopy = [ToolHelper copyWithText:text];
    if (isCanCopy) {
        
        [self showAlert:NSLocalizedString(@"copy_success", nil)];
    }
}

#pragma mark -- network

//获取公司详情
- (void)fetchContactPersonDetail {
    
    NSString * url = [NSString stringWithFormat:@"%@%@", kBaseUrl,
                      kContactPersonDetailUrl];
    NSString * contactId  = _contactId ? _contactId : @"";
    NSDictionary * dic = @{@"contactId": contactId };
    
    weakself(ws);
    [NetWorkHelper getWithURLString:url parameters:dic success:^(id object) {
        if (![object[@"code"] isEqual: kSuccessCode]) {
            
            NSString * info = [NSString isemptyStr:object[@"msg"]] ? kUnknownError : object[@"msg"];
            [ws showWithText:info];
            return;
        }
        ws.detailModel = [Contact_DetailModel yy_modelWithJSON:object[@"obj"]];
        
        [ws reConfigureHeaderViewName];
        [ws.tableView reloadData];
        
    } failure:^(NSError *error) {
        [ws showWithText:kNetworkError];
    }];
}

//获取联系人地址 私人地址isPrivate传1，办公地址传0
- (void)fetchContactAddressListIsPrivate:(BOOL)isPrivate {
    NSString * url = [NSString stringWithFormat:@"%@%@", kBaseUrl,
                      kCompanyDetailAddressListUrl];
    NSString * contactId  = _contactId ? _contactId : @"";
    
    NSString * isPrivateStr = isPrivate ? @"1" : @"0";
    NSDictionary * dic = @{@"contactId": contactId,
                           @"isPrivate": isPrivateStr};
    
    weakself(ws);
    [NetWorkHelper getWithURLString:url parameters:dic success:^(id object) {
        if (![object[@"code"] isEqual: kSuccessCode]) {
            NSString * info = [NSString isemptyStr:object[@"msg"]] ? kUnknownError : object[@"msg"];
            [ws showWithText:info];
            return;
        }
        NSArray * addressArray = [NSArray yy_modelArrayWithClass:[AddressModel class]
                                                            json:object[@"list"]];
        
        if (addressArray.count == 1) {
            AddressModel * model = addressArray[0];
            model.isShowArrow = YES;
        }
        
        if (isPrivate) {
            ws.privateAddressArray = addressArray;
        }else {
            ws.officeAddressArray = addressArray;
        }
        
        [ws.tableView reloadData];
        
    } failure:^(NSError *error) {
        [ws showWithText:kNetworkError];
    }];
    
}

//获取联系人角色
- (void)fetchContactPersonNum {
    NSString * url = [NSString stringWithFormat:@"%@%@", kBaseUrl,
                      kContact_Detail_Role_ListUrl];
    NSString * contactId  = _contactId ? _contactId : @"";
    
    NSDictionary * dic = @{@"contactId": contactId};
    
    weakself(ws);
    [NetWorkHelper getWithURLString:url parameters:dic success:^(id object) {
        if (![object[@"code"] isEqual: kSuccessCode]) {
            NSString * info = [NSString isemptyStr:object[@"msg"]] ? kUnknownError : object[@"msg"];
            [ws showWithText:info];
            return;
        }
        
        NSArray * addressArray = [NSArray yy_modelArrayWithClass:[Contact_RoleModel class]
                                                            json:object[@"list"]];
        ws.contactPersonsArray = addressArray;
        
//        if (addressArray.count > 0) {
            Contact_DetailHeaderView * header = (Contact_DetailHeaderView * ) ws.tableView.tableHeaderView;
            [header resetRoleNum:[NSString stringWithFormat:@"%ld", [addressArray count]]];
//        }
        
    } failure:^(NSError *error) {
        [ws showWithText:kNetworkError];
    }];
    
}

//获取礼物个数
- (void)fetchContactGifNum {
    NSString * url = [NSString stringWithFormat:@"%@%@", kBaseUrl, kContact_Detail_Gift_ListUrl];
    NSString * contactId  = _contactId ? _contactId : @"";
    NSDictionary * dic = @{@"contactId": contactId};
    
    weakself(ws);
    [NetWorkHelper getWithURLString:url parameters:dic success:^(id object) {
        if (![object[@"code"] isEqual: kSuccessCode]) {
            NSString * info = [NSString isemptyStr:object[@"msg"]] ? kUnknownError : object[@"msg"];
            [ws showWithText:info];
            return;
        }

        NSArray * addressArray = [NSArray yy_modelArrayWithClass:[GiftModel class]
                                                            json:object[@"list"]];
        ws.giftsArray = addressArray;
//        if (addressArray.count > 0) {
            Contact_DetailHeaderView * header = (Contact_DetailHeaderView * ) ws.tableView.tableHeaderView;
            [header resetGiftNum:[NSString stringWithFormat:@"%ld", [addressArray count]]];
//        }
        
    } failure:^(NSError *error) {
        [ws showWithText:kNetworkError];
    }];
    
}

//获取会议个数
- (void)fetchContactMeetingNum {
    NSString * url = [NSString stringWithFormat:@"%@%@", kBaseUrl,
                      kContact_Detail_Meeting_ListUrl];
    NSString * contactId  = _contactId ? _contactId : @"";
    NSDictionary * dic = @{@"contactId": contactId};
    
    weakself(ws);
    [NetWorkHelper getWithURLString:url parameters:dic success:^(id object) {
        if (![object[@"code"] isEqual: kSuccessCode]) {
            NSString * info = [NSString isemptyStr:object[@"msg"]] ? kUnknownError : object[@"msg"];
            [ws showWithText:info];
            return;
        }
        NSArray * addressArray = [NSArray yy_modelArrayWithClass:[Com_MeetingModel class]
                                                            json:object[@"list"]];
        ws.meetingsArray = addressArray;
//        if (addressArray.count > 0) {
            Contact_DetailHeaderView * header = (Contact_DetailHeaderView * ) ws.tableView.tableHeaderView;
            [header resetMeetingNum:[NSString stringWithFormat:@"%ld", [addressArray count]]];
//        }
        
    } failure:^(NSError *error) {
        [ws showWithText:kNetworkError];
    }];
    
}
//获取联系人系统记录
- (void)fetchContactReportList {
    NSString * url = [NSString stringWithFormat:@"%@%@", kBaseUrl,
                      kContact_Detail_Report_ListUrl];
    //    NSString * accountId = self.personModel ? (self.personModel.id ?
    //                                               self.personModel.id : @"" ) : @"";
    NSString * accountId = _contactId ? _contactId : @"";
    NSDictionary * dic = @{@"contactId": accountId};
    
    weakself(ws);
    [NetWorkHelper getWithURLString:url parameters:dic success:^(id object) {
        if (![object[@"code"] isEqual: kSuccessCode]) {
            NSString * info = [NSString isemptyStr:object[@"msg"]] ? kUnknownError : object[@"msg"];
            [ws showWithText:info];
            return;
        }
        
        NSArray * addressArray = [NSArray yy_modelArrayWithClass:[Contact_ReportModel class]
                                                            json:object[@"list"]];
        
        ws.reportArray = addressArray;
        //        if (addressArray.count > 0) {
        Contact_DetailHeaderView * header = (Contact_DetailHeaderView * ) ws.tableView.tableHeaderView;
        [header resetGiftNum:[NSString stringWithFormat:@"%ld", [addressArray count]]];
        
        //        }
    } failure:^(NSError *error) {
        [ws showWithText:kNetworkError];
    }];
}
- (void)editContactMethod {
    Add_Manual_ContactViewController * contactVC = [Add_Manual_ContactViewController new];
    contactVC.pageStyle = PageStyleEdit;
    contactVC.detailModel = _detailModel;
    contactVC.accountId = _detailModel.accountId;;
    [self.navigationController pushViewController:contactVC animated:YES];
}

//编辑私人信息
- (void)editPrivateInfo {
    EditPrivateInfoViewController * workInfoVc = [EditPrivateInfoViewController new];
    workInfoVc.contactId = _contactId;
    workInfoVc.detailModel = _detailModel;
    [self.navigationController pushViewController:workInfoVc animated:YES];
}

//编辑工作信息
- (void)editWorkInfo {
    EditWorkInfoViewController * workInfoVc = [EditWorkInfoViewController new];
    workInfoVc.contactId = _contactId;
//    workInfoVc.accountId= _detailModel.accountId;
    workInfoVc.detailModel = _detailModel;
    [self.navigationController pushViewController:workInfoVc animated:YES];
}
@end
